
# 数据库配置信息
# 数据库类型--mysql
DIALECT = 'mysql'
# 数据库驱动--mysql驱动
DRIVER = 'pymysql'
# 数据库用户名
USERNAME = 'root'
# 数据库密码
PASSWORD = '123456'
# 数据库主机
HOST = '127.0.0.1'
# 数据库端口
PORT = '3306'

#开发数据库
DEV_DATABASE = 'test123' 
#测试数据库     
TEST_DATABASE = 'test123'  
#生产数据库   
PRODUCT_DATABASE = 'test123'  

# 数据库连接格式
DB_URL = "{}+{}://{}:{}@{}:{}/".format(DIALECT,
                                       DRIVER, USERNAME, PASSWORD, HOST, PORT)
#数据库编码                                     
CHARSET = "?charset=utf8"

# 通用配置
class Config:
    # flask--secrt_key
    SECRET_KEY = "e2ca2ec1066c1738647be11770b55be53f455f3ee33645cfb9d030e1976bd1bb"

    # 返回json数据显示中文
    JSON_AS_ASCII=False
    
    # SQLALCHEMY配置
    SQLALCHEMY_COMMIT_ON_TEARDOWN = False
    SQLALCHEMY_TRACK_MODIFICATIONS=True

    # 发送邮件配置
    FLASKY_MAIL_SUBJECT_PREFIX = '[Flasky]'
    FLASKY_MAIL_SENDER = 'Flasky Admin <flasky@example.com>'
    FLASKY_ADMIN = 'FLASKY_ADMIN'
    MAIL_SERVER = 'smtp.googlemail.com'
    MAIL_PORT = 587
    MAIL_USE_TLS = True
    MAIL_USERNAME = 'MAIL_USERNAME'
    MAIL_PASSWORD = 'MAIL_PASSWORD'

    # 有效期配置
    TOKEN_EXPIRATION=7*24*3600 #配置token过期信息

    # redis配置
    # token--reids前缀
    REDIS_PREFIX='token_auth_'
    # redies主机
    REDIS_HOST = 'localhost'
    # redis端口
    REDIS_PORT = '6379'
    # redis密码
    REDIS_PASSWORD = 'root123'

    # celery配置
    # 中间人broker链接--redis
    CELERY_BROKER_URL='{}://{}:{}/{}'.format('redis',REDIS_HOST, REDIS_PORT,3)  # 'redis://localhost:6379/3'
    # 结果链接--redis
    CELERY_RESULT_BACKEND = '{}://{}:{}/{}'.format('redis',REDIS_HOST, REDIS_PORT,4)  # 'redis://localhost:6379/8'
 
 
    @staticmethod
    def init_app(app):
        pass


# 开发环境配置
class DevelopmentConfig(Config):
    DEBUG = True
    DATABASE = DEV_DATABASE
    SQLALCHEMY_DATABASE_URI = DB_URL+DATABASE + CHARSET



# 测试环境配置
class TestingConfig(Config):
    TESTING = True
    DATABASE = TEST_DATABASE
    SQLALCHEMY_DATABASE_URI = DB_URL+DATABASE + CHARSET



# 线上环境配置
class ProductionConfig(Config):
    DATABASE = PRODUCT_DATABASE
    SQLALCHEMY_DATABASE_URI = DB_URL+DATABASE + CHARSET


config = {
    'development': DevelopmentConfig,
    'testing': TestingConfig,
    'production': ProductionConfig,
    'default': DevelopmentConfig
}
